home *** CD-ROM | disk | FTP | other *** search
- /*
- File: CCounterApp.cp
-
- Contains: Sample code to accompany Chapter 12 of
- "An Introduction to Macintosh Programming for Windows Programmers".
-
- Written by: Worldwide Developer Technical Support
-
- Copyright: 1999 Apple Computer, Inc., All Rights Reserved
-
- You may incorporate this sample code into your applications without
- restriction, though the sample code has been provided "AS IS" and the
- responsibility for its operation is 100% yours. However, what you are
- not permitted to do is to redistribute the source as "DSC Sample Code"
- after having made changes. If you're going to re-distribute the source,
- we require that you make it clear in the source that the code was
- descended from Apple Sample Code, but that you've made changes.
-
- */
-
- #include "CCounterApp.h"
- #include "CounterConstants.h"
- #include "CCounterDocument.h"
- #include <LSIOUXAttachment.h>
- #include <iostream.h>
-
- #include <LStaticText.h>
-
- #include <LGrowZone.h>
- #include <LWindow.h>
- #include <PP_Messages.h>
- #include <PP_Resources.h>
- #include <PPobClasses.h>
- #include <UDrawingState.h>
- #include <UMemoryMgr.h>
- #include <URegistrar.h>
- #include <UModalDialogs.h>
-
- #include <UControlRegistry.h>
- #include <UGraphicUtils.h>
- #include <UEnvironment.h>
-
- #ifndef __APPEARANCE__
- #include <Appearance.h>
- #endif
-
- #include <Sound.h>
- #include <ToolUtils.h>
-
- // ===========================================================================
- int main()
- {
- SetDebugThrow_(debugAction_Alert);
- SetDebugSignal_(debugAction_Alert);
- InitializeHeap(3); // allocate 3 Master Pointer blocks
- UQDGlobals::InitializeToolbox(&qd);
- UEnvironment::InitEnvironment();
- new LGrowZone(20000); // For low memory situations.
- CCounterApp theApp; // stack allocation
- theApp.Run();
- return 0;
- }
-
- // ---------------------------------------------------------------------------
- CCounterApp::CCounterApp()
- {
- if ( UEnvironment::HasFeature( env_HasAppearance ) ) {
- ::RegisterAppearanceClient();
- }
- RegisterAllPPClasses(); // functions to create core PowerPlant classes
- UControlRegistry::RegisterClasses(); // Appearance Manager/GA classes
- AddAttachment(new LSIOUXAttachment); // Use SIOUX Attachment
- }
-
-
- // ---------------------------------------------------------------------------
- CCounterApp::~CCounterApp()
- {
- }
-
- // ---------------------------------------------------------------------------
- // This function lets you do something when the application starts up
- // without a document.
- void
- CCounterApp::StartUp()
- {
- ObeyCommand(cmd_New, nil);
- }
-
- // ---------------------------------------------------------------------------------
- void
- CCounterApp::OpenDocument(FSSpec* inMacFSSpec )
- {
- LDocument* theDoc = LDocument::FindByFileSpec(*inMacFSSpec);
- if (theDoc != nil) { // Document is already open
- theDoc->MakeCurrent(); // Make it the current document
- } else { // Make a new Document
- theDoc = new CCounterDocument(this, inMacFSSpec);
- }
- }
-
- // ---------------------------------------------------------------------------------
- LModelObject*
- CCounterApp::MakeNewDocument()
- {
- FSSpec* spec = nil;
- return new CCounterDocument(this, spec);
- }
-
- // ---------------------------------------------------------------------------------
- void
- CCounterApp::ChooseDocument()
- {
- UDesktop::Deactivate();
- SFTypeList theTypeList = {kDocType};
- StandardFileReply theReply;
- ::StandardGetFile( nil, 1, theTypeList, &theReply );
- UDesktop::Activate();
- if (theReply.sfGood) { // if not canceled
- SendAEOpenDoc(theReply.sfFile); // send AppleEvent to open the document
- }
- }
-
- // ---------------------------------------------------------------------------------
- void
- CCounterApp::PrintDocument(FSSpec* inMacFSSpec )
- {
- CCounterDocument* theDocument = new CCounterDocument(this, inMacFSSpec);
- theDocument->DoPrint();
- }
-